package news.controller;


import news.service.AddPublishServiceImpl;
import news.service.IAddPublishService;
import news.service.ISelPublishService;
import news.service.SelPublishServiceImpl;
import news.util.BaseHttpServlet;
import news.util.FileUtils;
import news.util.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author JiangJ
 * @date 2022/2/28 20:15
 * 分页
 */
@WebServlet("/selPublish")
public class NewsInfoPageController extends BaseHttpServlet {
    private final ISelPublishService iSelPublishService = new SelPublishServiceImpl();
    private static final long serialVersionUID = 1L;

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应内容类型
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("utf-8");
        //分页查询数据库数据集合
        PageBean pageBean = new PageBean();

        int pageIndex = request.getParameter("pageIndex") != null ? Integer.parseInt(request.getParameter("pageIndex")) : 1;

        int count = iSelPublishService.calcTotalCount();

        pageBean.setCurrPageNo(pageIndex);

        pageBean.setTotalCount(count);


        PageBean pageInfo = iSelPublishService.getNewsPublishPageList(pageBean);

        request.setAttribute("pageInfo", pageInfo);

        //3.返回成功响应

        request.getRequestDispatcher(request.getContextPath() + "/news/main/news_content.jsp").forward(request, response);

    }
}
